/**
 * Created by Administrator on 2016/3/11 0011.
 */

function checkifnull(str) {
    if (str == null) {
        return "暂无数据";
    } else {
        return str;
    }
}

$(function () {

    $("#counttable").hide();
    searchEnergy();

    function searchEnergy() {
        $.ajax({
            url: 'excuteCountManyAjax.shtml?' + $.param($("#countForm").serializeObject()),
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data != null && data.length > 0) {
                    $("#nodatas").hide();
                    $("#counttable").show();
                    $("#countcompanycode td:gt(0)").remove();
                    $("#countcustomername td:gt(0)").remove();
                    $("#countemployeenum td:gt(0)").remove();
                    $("#countsquare td:gt(0)").remove();
                    $("#countstreet td:gt(0)").remove();
                    $("#countrealpower td:gt(0)").remove();
                    $("#countlightpower td:gt(0)").remove();
                    $("#countairpower td:gt(0)").remove();
                    $("#countunitsquare td:gt(0)").remove();
                    $("#countunitperson td:gt(0)").remove();
                    _.pluck(data, 'companycode');
                    $.each(data, function (item, element) {
                        $("#countcompanycode").append("<td>" + checkifnull(_.pluck(data, 'companycode')[item]) + "</td>");
                        $("#countcustomername").append("<td>" + checkifnull(_.pluck(data, 'customername')[item]) + "</td>");
                        $("#countemployeenum").append("<td>" + checkifnull(_.pluck(data, 'employeenum')[item]) + "</td>");
                        $("#countsquare").append("<td>" + checkifnull(_.pluck(data, 'square')[item]) + "</td>");
                        $("#countstreet").append("<td>" + checkifnull(_.pluck(data, 'street')[item]) + "</td>");
                        $("#countrealpower").append("<td>" + checkifnull(_.pluck(data, 'realpower')[item]) + "</td>");
                        $("#countlightpower").append("<td>" + checkifnull(_.pluck(data, 'lightpower')[item]) + "</td>");
                        $("#countairpower").append("<td>" + checkifnull(_.pluck(data, 'airpower')[item]) + "</td>");
                        $("#countunitsquare").append("<td>" + checkifnull(_.pluck(data, 'unitsquare')[item]) + "</td>");
                        $("#countunitperson").append("<td>" + checkifnull(_.pluck(data, 'unitperson')[item]) + "</td>");
                    });
                } else {
                    $("#nodatas").show();
                    $("#counttable").hide();
                }
            }
        })
    }
});